package com.hoopeu.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hoopeu.db.DBDataMamager;
import com.hoopeu.device.BaseDevice;
import com.hoopeu.device.MBDevice;
import com.hoopeu.entity.Device;
import com.hoopeu.smarthome.R;




public class MaskAdapter extends BaseAdapter
{
  private Context mContext;
  private List<Device> MaskList;

  public MaskAdapter(Context context)
  {
    this.mContext = context;
   this.MaskList =  DBDataMamager.findDeviceByDeviceType(mContext, "MB");
  }

  public int getCount()
  {
    return this.MaskList.size();
  }

  public Object getItem(int index)
  {
    return null;
  }

  public long getItemId(int index)
  {
    return index;
  }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
	// TODO Auto-generated method stub
	View view = convertView;
	ViewHolder mHolder;
	
	final BaseDevice device;
	if(view == null)
	{
		mHolder = new ViewHolder();
		view = LayoutInflater.from(mContext).inflate(R.layout.maskadapter, parent,false);
		mHolder.maskName = (TextView)view.findViewById(R.id.tvMaskName);
		mHolder.llMaskOpen = (LinearLayout)view.findViewById(R.id.llMaskOpen);
		mHolder.llMaskClose = (LinearLayout)view.findViewById(R.id.llMaskClose);
		view.setTag(mHolder);
	}
	else
		mHolder = (ViewHolder)view.getTag();
	//id name type
	String name = this.MaskList.get(position).getName();
	String deviceId = this.MaskList.get(position).getId();
	if(name == null)
		name = "";
	device = new MBDevice(mContext, deviceId);
	mHolder.maskName.setText(name);
	
	mHolder.llMaskOpen.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			device.sendForOpen();
		}
	});
	
mHolder.llMaskClose.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			device.sendForClose();
		}
	});
	
	return view;
}

class ViewHolder
{
	TextView maskName;
	LinearLayout llMaskOpen;
	LinearLayout llMaskClose;
	}
 /* public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    LayoutInflater localLayoutInflater = (LayoutInflater)this.context.getSystemService("layout_inflater");
    String[] arrayOfString = (String[])this.lightList.get(paramInt);
    this.showHandle.OpenDb();
    final ArrayList<String[]> localArrayList = this.showHandle.getDeviceKey(arrayOfString[0]);
    this.showHandle.CloseDb();
    View localView = localLayoutInflater.inflate(R.layout.maskadapter, null);
    LinearLayout localLinearLayout1 = (LinearLayout)localView.findViewById(R.id.btnOpen);
    if ((arrayOfString[0] != null) && (!"".equals(arrayOfString[0])))
      localLinearLayout1.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
       //   MaskAdapter.this.mCommandCommunicate.send(((String[])localArrayList.get(0))[3]);
        }
      });
    LinearLayout localLinearLayout2 = (LinearLayout)localView.findViewById(R.id.btnClose);
    if ((arrayOfString[0] != null) && (!"".equals(arrayOfString[0])))
      localLinearLayout2.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
        //  MaskAdapter.this.mCommandCommunicate.send(((String[])localArrayList.get(1))[3]);
        }
      });
    ((TextView)localView.findViewById(R.id.tvMaskName)).setText(arrayOfString[1]);
    return localView;
  }*/
}
